<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <title></title>
    <%@include file="/WEB-INF/pages/common/basic-styles.jspf" %>
</head>
<body>
    <form:form id="form" method="post" commandName="organization" cssClass="form-horizontal" cssStyle="padding-top:20px;">
        <form:hidden path="id"/>
        <form:hidden path="available"/>
        <form:hidden path="parentId"/>
        <form:hidden path="parentIds"/>
        
        <div class="form-group">
			<label class="col-sm-1 control-label" for="name"> 名称 </label>
			<div class="col-sm-9">
				<form:input path="name" class="col-xs-10 col-sm-5" />
				<span class="help-inline col-xs-12 col-sm-7">
					<span class="middle"></span>
				</span>
			</div>
		</div>
		<div class="space-4"></div>
        
        <div style="padding-left: 20px;">
        <shiro:hasPermission name="organization:update">
            <form:button id="updateBtn" class="btn btn-sm btn-primary">修改</form:button>
        </shiro:hasPermission>

        <shiro:hasPermission name="organization:delete">
            <c:if test="${not organization.rootNode}">
            <form:button id="deleteBtn" class="btn btn-sm btn-primary">删除</form:button>
            </c:if>
        </shiro:hasPermission>

        <shiro:hasPermission name="organization:create">
            <form:button id="appendChildBtn" class="btn btn-sm btn-primary">添加子节点</form:button>
        </shiro:hasPermission>

        <shiro:hasPermission name="organization:update">
            <c:if test="${not organization.rootNode}">
            <form:button id="moveBtn" class="btn btn-sm btn-primary">移动节点</form:button>
            </c:if>
        </shiro:hasPermission>
        </div>
    </form:form>

	<%@include file="/WEB-INF/pages/common/basic-scripts.jspf" %>  
    <script>
        $(function() {
            $("#updateBtn").click(function() {
            	var name = $("#name").val();
            	if (isEmpty(name)) {
            		defaultAlert("组织机构名称不能为空");
            		return false;
            	}
            	loading();
                $("#form").attr("action", "${ctx}/manage/system/organization/update/${organization.id}")
                        .submit();
                return false;
            });
            
            $("#deleteBtn").click(function() {
            	defaultConfirm("确定要删除吗?", function(result) {
    				if (result) {
    					loading();
    					$("#form").attr("action", "${ctx}/manage/system/organization/delete/${organization.id}")
                        .submit();
    				}
            	});
                return false;
            });

            $("#appendChildBtn").click(function() {
                location.href = "${ctx}/manage/system/organization/appendChild/${organization.id}";
                return false;
            });

            $("#moveBtn").click(function() {
                location.href="${ctx}/manage/system/organization/move/${organization.id}";
                return false;
            });
        });
    </script>
</body>
</html>